package com.ajview.core.manage;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

/**
 * PROJECT_NAME: ajview-smile
 *
 * @DESCRIPTION: 管理器关闭
 * @DATE 2022-12-28 上午 01:10
 * @Author zhangjunjie
 */
@Component
@Slf4j
public class ShutdownManager {

    /**
     * 销毁servlet时会调用该方法
     */
    @PreDestroy
    public void destroy() {
        shutdownAsyncManager();
    }

    /**
     * 停止异步执行任务
     */
    private void shutdownAsyncManager() {
        try {
            log.info("====关闭后台任务任务线程池====");
            AsyncManager.getInstance().shutdown();
        } catch (Exception e) {
            log.error("关闭后台任务任务线程池错误！错误原因:{}<-", e.getMessage(), e);
        }
    }
}
